package engine.newUi
{
	import engine.control.TurnPapersViewGroup;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.ResPath;
	import engine.data.View;
	import engine.data.ViewObject;
	import engine.event.SoundEvent;
	import engine.flag.GameDefine;
	import engine.flag.ResourcesPath;
	import engine.logic.event.LogicEvent;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneManager;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	import engine.ui.MsgTipsLogic;
	import engine.util.FilterUtil;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import newx.BaseObject;
	import newx.NxApi;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.tab.NxTabEvent;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	
	//import org.hamcrest.collection.array;

	/**
	 * 装备精炼逻辑类 
	 * @author wanghb
	 * 
	 */
	public class EquipModifiedLogic
	{
		private static var _self		:EquipModifiedLogic;
		private var _myDisplay			:EquipModifiedUI;
		private var _model				:ModelLocator
		private var _bindManage		:BindManage;
		private var _friendnObj		:Object;
		private var _friendTabArray	:Array;
		private var _viewGroupTrun		:TurnPapersViewGroup;
		private var _viewID			:int	=	-1;
		private var _bindIndex			:int	=	-1;
		private var _friendEquipObj	:Object;
		private var _friendEquipArray	:Array
		private var __chooseEquip		:Object	=	null;
		private var _CDTimer			:int	=	0
		private var _col				:int;
		private var _roleBaseObj:BaseObject;
		private var _packBaseObj:BaseObject;
		private var _oldMC:MovieClip	=	null;
		private var _bindChooseIndex:int	=	-1;
		private var _levelMax:Boolean	=	false;
		private var _isNeedMoeny:Boolean	=	true;
		private var _isNowItem:Boolean		=	false;
		private var _oldClickItem:MovieClip;
		private const COLOR_TABLE	:Array	=	["","#ffffff'>","#1eff00'>","#20BFF8'>","#a335ee'>","#E8912E'>","#e5cc80'>","#ffff00'>"];
		private var _levelUpdate:Boolean = true; 
		
		// 一键强化 固定升5级
		private const INTENSITY_LEVEL:int  = 5 ; 
		
		//钱够强化五级 就是true 不够强化五级 就false
		private var _GoldIs:Boolean =false ; 
		public function get _chooseEquip():Object 
		{
			return __chooseEquip;
		}
		public function set _chooseEquip(value:Object):void 
		{
			if(value==null)
			{
//				trace((new Error).getStackTrace());
//				return
			}
			__chooseEquip=value
		}
		
		private var _blindFlag:int = -1 ; 
		private var _tabArr:Array=[] ;
		/**每个人物的装备个数**/
		private var _itemMax:uint ; 
		/***材料数组**/
		private var _stuffArr:Array=[];
		/**当前强化的等级***/
		private var addLv:uint ; 
		/**所制作装备的Tips**/
		private var Tips:Object; 
		/**人物身上有的装备***/
		private var arrEquip:Array= [];
		/***人物物理类型**/
		private var peoType:uint ; 
		/***当前任务的武器类型**/
		private var weap:int ; 
		/***立即完成需要的元宝数***/
		private var _needMagicCoin:int = 0 ; 
		/**强化新手引导**/
		private var _tipsShow:Boolean = false; 
		/****记录当前你所点的是直接强化还是强化按钮***/
		private var _btnMc:MovieClip; 
		public function EquipModifiedLogic()
		{
			
			_friendTabArray	=	[];
			_friendnObj		=	{};
			_roleBaseObj	=	new BaseObject();
			_packBaseObj	=	new BaseObject();
			
			_roleBaseObj.HandleProperties("viewID",View.VIEWPORT_EQUIP);
			_roleBaseObj.HandleProperties("ConfigID",-1)
				
			_packBaseObj.HandleProperties("viewID",View.VIEWPORT_TOOL);
			_packBaseObj.HandleProperties("ConfigID",-2);
			
			//展示不用CD时间了
//			PlayCDTimerLogic.getInstance().resgis(3,checkCDTimer);
			_bindManage		=	BindManage.getInstance();
			_model			=	ModelLocator.getInstance();
			_myDisplay		=	EquipModifiedUI.getInstance();
			/**装备格子数**/
			_itemMax 		= _myDisplay.itemGroup.col*_myDisplay.itemGroup.row; 
			
			_myDisplay.itemGroup.addChild(_myDisplay.effectMc);
			_myDisplay.effectMc.visible	=	false;
			_blindFlag		=_bindManage.BindRecord(_model.scene,"LineupRecord",onaddPerHandle,onremovePerHandle);
			
			_bindManage.BindView(_model.scene,View.VIEWPORT_PARTNER,addItem,removeItem);
			_viewGroupTrun	=	new TurnPapersViewGroup(_myDisplay.itemGroup,_myDisplay.preBtn,_myDisplay.nextBtn,showEquipItem,removeMcEquipItem,afterShowItem,_myDisplay.pageNum);
			inforViewGroup();
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_AUTO_BUY_MATRIAL),getConsume)	
			/**初始化制作装备材料显示格子**/
			awardInfo();
			showClickEquip(null,null)

	
		}
		
		public static function getInstance():EquipModifiedLogic
		{
			if(_self == null)
			{
				_self = new EquipModifiedLogic();
			}
			return _self;
		}
		/**
		 * 添加事件
		 */		
		public function addListener():void
		{
			_myDisplay.effect.gotoAndStop(1)
			_myDisplay.effect.visible	=	false;
			_myDisplay.btn_start.	addEventListener(	MouseEvent.CLICK ,			btnClickHandle);
			_myDisplay.windowBG.	addEventListener(	NxWindowEvent.WINDOW_CLOSE, windowCloseHandle);
			_myDisplay.roleTab.		addEventListener(	NxTabEvent.TAB_CLICK, 		tabClickHandle);
			_myDisplay.itemGroup.	addItemsEvent(		MouseEvent.CLICK, 			viewClickHandle);
			_myDisplay.itemGroup.	addItemsEvent(		MouseEvent.MOUSE_OVER, 		viewOverHandle);
			_myDisplay.itemGroup.	addItemsEvent(		MouseEvent.MOUSE_OUT, 		viewOutHandle);
			_myDisplay.equipPic.	addEventListener(	MouseEvent.ROLL_OVER,		clipOverHandle);
			_myDisplay.equipPic.	addEventListener(	MouseEvent.ROLL_OUT	,		clipOutHandle);
			/**材料搜集****/
			_myDisplay.stuff.addItemsEvent(MouseEvent.CLICK,ClickHandler) ; 
			/**材料的Tips***/
			_myDisplay.stuff.addItemsEvent(MouseEvent.MOUSE_OVER,onShowTips);
			_myDisplay.stuff.addItemsEvent(MouseEvent.MOUSE_OUT,onHideTips);
			/***立即购买**/
			_myDisplay.btn_3.addEventListener(MouseEvent.CLICK,buyEquipHandler); 
			/****btn_2*立即穿戴*/
			_myDisplay.btn_2.addEventListener(MouseEvent.CLICK,buyEquipHandler);
			/**btn_1*制作**/
			_myDisplay.btn_1.addEventListener(MouseEvent.CLICK,buyEquipHandler);
			_myDisplay.btn_4.addEventListener(MouseEvent.CLICK,buyEquipHandler);
			
			_myDisplay.btn_4.addEventListener(MouseEvent.MOUSE_OUT,outEquipHandler);
			_myDisplay.btn_4.addEventListener(MouseEvent.MOUSE_OVER,overEquipHandler);
			
			_myDisplay.equipPic_1.addEventListener(MouseEvent.ROLL_OVER	,tipsOverHandle);
			_myDisplay.equipPic_1.addEventListener(MouseEvent.ROLL_OUT	,	tipsOutHandle);
			//一键强化
			_myDisplay.updateStart.addEventListener(MouseEvent.CLICK,updateStartHandler);
			_myDisplay.updateStart.addEventListener(MouseEvent.MOUSE_OUT,outEquipHandler);
			_myDisplay.updateStart.addEventListener(MouseEvent.MOUSE_OVER,overEquipHandler);
				
				
				
			_viewGroupTrun.addListener();
			showTab();
			//记录你当前所选的伙伴强化装备
			var value_1:int  = _myDisplay.roleTab.selected	;
			_myDisplay.roleTab.selected	=	value_1;
			
			if(_tipsShow==false)
			{
				_myDisplay.gogo.visible =false ; 
			}
			if(!SceneManager._itemIconLoad)
			{
				_model.addEventListener(LogicEvent.ITEMICONLOADED,loaded);
				function loaded():void
				{
					var value:int  = _myDisplay.roleTab.selected	;
					_myDisplay.roleTab.selected	=	value;
					_model.removeEventListener(LogicEvent.ITEMICONLOADED,loaded)
				}
			}
			
		}
		/**
		 *删除事件 
		 */		
		public function removeListener():void
		{
			_myDisplay.btn_start.	removeEventListener(	MouseEvent.CLICK ,				btnClickHandle);
			_myDisplay.windowBG.	removeEventListener(	NxWindowEvent.WINDOW_CLOSE, 	windowCloseHandle);
			_myDisplay.roleTab.		addEventListener(		NxTabEvent.TAB_CLICK, 			tabClickHandle);
			_myDisplay.itemGroup.	removeItemsEvent(		MouseEvent.CLICK, 				viewClickHandle);
			_myDisplay.equipPic.	removeEventListener(	MouseEvent.ROLL_OVER,		clipOverHandle);
			_myDisplay.equipPic.	removeEventListener(	MouseEvent.ROLL_OUT	,		clipOutHandle);
			
			/**材料搜集****/
			_myDisplay.stuff.removeItemsEvent(MouseEvent.CLICK,ClickHandler) ; 
			/**材料的Tips***/
			_myDisplay.stuff.removeItemsEvent(MouseEvent.MOUSE_OVER,onShowTips);
			_myDisplay.stuff.removeItemsEvent(MouseEvent.MOUSE_OUT,onHideTips);
			/***立即购买**/
			_myDisplay.btn_3.removeEventListener(MouseEvent.CLICK,buyEquipHandler); 
			/****btn_2*立即穿戴*/
			_myDisplay.btn_2.removeEventListener(MouseEvent.CLICK,buyEquipHandler);
			/**btn_1*制作**/
			_myDisplay.btn_1.removeEventListener(MouseEvent.CLICK,buyEquipHandler);
			
			_myDisplay.equipPic_1.removeEventListener(MouseEvent.ROLL_OVER	,tipsOverHandle);
			_myDisplay.equipPic_1.removeEventListener(MouseEvent.ROLL_OUT	,	tipsOutHandle);
			_viewGroupTrun.removeListener();
			_tipsShow = false ;
		}
		/**
		 * 开始精炼
		 * @param e
		 * 
		 */		
		//当前你所点击的是哪个按钮
		private var currBtn:NxButton ; 
		private function btnClickHandle(e:MouseEvent):void
		{
			if((e.currentTarget as NxButton).label	==	StaticIni.getSwfLangStr("UIString_1000636"))
			{
				currBtn=e.currentTarget as NxButton;
				if(_chooseEquip != null)
				{
					//用在屏蔽快速点击的操作
//					_CDTimer	=	1000;
//					_myDisplay.btn_start.enabled	=	false;
					
					if(_levelUpdate)
					{
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_UPGRADE_EQUIP,_chooseEquip["viewID"],int(_chooseEquip["data"]["ObjKey"]));
//						MsgTipsLogic.getRes((e.currentTarget as NxButton),0).showInfo("强化成功",false);
						_levelUpdate =false ;  
						
					}
					
					
					_model.dispatchEvent(new SoundEvent(SoundEvent.EQUIP_UP));
				}
			}
			else if((e.currentTarget as NxButton).label	==	StaticIni.getSwfLangStr("UIString_1000637"))
			{
				//清除强化的CD时间
				SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLEINT_CUSTOMMSG_REQUEST_CLEAR_CD,[3,_col]);
			}
		}
		/**
		 *购买 、 制作 
		 * @param e
		 * 
		 */		
		private function buyEquipHandler(e:MouseEvent):void
		{
			var obj:Object ={};
		
			if(e.currentTarget==_myDisplay.btn_3)/**立即购买**/
			{
				/**
				 * 1 -- 装备id
					2 -- 视图id
				 * **/
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_BUY_EQUIP_WARE,int(_chooseEquip["ConfigID"]),_viewID);
				//.obj=
			}else if(e.currentTarget==_myDisplay.btn_2)/**立即穿戴***/
			{
				obj = _chooseEquip//["data"] as Object
//				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_BUY_EQUIP_WARE ,(obj as ObjectData).GetPropertiesEx("ConfigID"),_viewID);
				PackLogic.getInstance().equip(obj as ViewObject,_viewID);
				
			}else if(e.currentTarget==_myDisplay.btn_1)/****制作*****/
			{
				/***
				 * 1 -- 2
					2 -- 卷轴id UpgradeScroll
					3 -- 视图类型
					4 -- 装备所在位置
					5 -- 1
				 * 
				 * */
				obj = _chooseEquip["data"] as Object
				GameDefine.EQPOS_HASH_MAP[(obj as ObjectData).GetPropertiesEx("EquipType")];
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_COMPOSE_ITEM,2,(obj as ObjectData).GetPropertiesEx("UpgradeScroll") ,_viewID,GameDefine.EQPOS_HASH_MAP[(obj as ObjectData).GetPropertiesEx("EquipType")]);
			}	
			else if(e.currentTarget==_myDisplay.btn_4)/****立即制作*****/
			{
				AlertUI.showAlert("",StaticIni.getSwfLangStrVar("UIString_1000486",[ComposeItemLogic.getInstance().needMagicCoin]),AlertUI.YES|AlertUI.NO,clickBack)
			}

		}
		private function clickBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.YES == type)//确定立即制作
			{
				/**
				 * 发放开始制造消息 
				 * @param obj  制造的物品
				 * @param type 类型  1 是点击背包制作  2点击装备
				 * @param viewtype  视图ID
				 * @param MsgType	1 普通制作 2立即完成
				 */		
				var obj:Object = _chooseEquip["data"] as Object
				if(ComposeItemLogic.getInstance().searchItem(obj["Properties"]["UpgradeScroll"],1)!=0)
				{
					
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_COMPOSE_ITEM,2,obj["Properties"]["UpgradeScroll"],_viewID,GameDefine.EQPOS_HASH_MAP[(obj as ObjectData).GetPropertiesEx("EquipType")],2);
				}else
				{
					NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000520")); 
				}
				
			}
		}
		private function ClickHandler(e:MouseEvent):void
		{
			var MC:MovieClip	=	e.currentTarget as MovieClip;
			var obj:Object		=	StaticIni.getIniObj(MC["configID"].toString());
			
			if(obj !=null)
			{
				if(obj is ViewObject)
				{
					return;
				}
			}
			if(obj != null && obj.ItemType == GameDefine.ItemType_Material||obj.ItemType == GameDefine.ItemType_COMPOSE)
			{
				if(obj.ItemType == GameDefine.ItemType_COMPOSE&&_model.scene.Role.getPlayerLevel()>=21)
				{
					EliteFBUI.getInstance().showOrHide();
				}else
				{
					var fbId : String = obj["FBID"];
					var sceneId : String = obj["TargetScene"];
					DuplicatesLogic.getInstance().FBSceneID(sceneId,DuplicatesLogic.COLL_FB);
					DuplicatesLogic.getInstance().showInfo( fbId );
				}
				
			}
		}
		/***立即完成***/
		private function outEquipHandler(e:MouseEvent):void
		{
			
			TipsMainLogic.instance.hide();
			
			
		}
		private function overEquipHandler(e:MouseEvent):void
		{
			var obj:Object = _chooseEquip["data"] as Object
			var blueConsume:int  =0 ; 
		
			if(e.currentTarget == _myDisplay.updateStart)
			{
//				blueConsume = 15 + 3 * Math.pow(obj["IntensityLevel"], 2);
				//当前等级的后五级的铜钱数
				blueConsume = getAddFiveLv(obj["Properties"])
			
				if(_model.scene.Role.getGoldCoin()>= blueConsume)
				{
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000682" ,[blueConsume])) ; 
				}else
				{
					//钱不够五级 显示红色的字
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000682" ,[blueConsume])) ; 
				}
				
			}else if(e.currentTarget == _myDisplay.btn_4)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_SCROLL_PRODUCITON_UI,2,obj["Properties"]["UpgradeScroll"],_viewID,GameDefine.EQPOS_HASH_MAP[(obj as ObjectData).GetPropertiesEx("EquipType")]);
			}
			
		}
		/**
		 *材料Tips 显示 
		 * @param e
		 * 
		 */		
		private function onShowTips(e:MouseEvent):void
		{
			 var itemMC:MovieClip = e.currentTarget as MovieClip ; 
			 TipsMainLogic.instance.showMain(itemMC["configID"]);
		}
		private function onHideTips(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * CD时间 
		 * @param val
		 * 
		 */		
		public function checkCDTimer(val:int,col:int):void
		{
			_CDTimer	=	val;
			_col		=	col;
			if(_CDTimer == 0)
			{
				_myDisplay.btn_start.label			=	StaticIni.getSwfLangStr("UIString_1000638");
				if(_chooseEquip != null  && _isNeedMoeny && !_levelMax)
				{
					_myDisplay.btn_start.enabled	=	true;
				}
				else
				{
					_myDisplay.btn_start.enabled	=	false;
				}
//				_myDisplay.lab_cdtime.htmlText		=	"";
			}
			else
			{
				if(_isNeedMoeny && !_levelMax)
				{
					_myDisplay.btn_start.enabled	=	true;
					_myDisplay.btn_start.label		=	StaticIni.getSwfLangStr("UIString_1000637");
					
//					_myDisplay.lab_cdtime.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_4",[PlayCDTimerLogic.getInstance().getTimerStr(_CDTimer)]);
				}
				else
				{
					_myDisplay.btn_start.enabled	=	false;
				}
			}
		}
		private var _itemGroupItem:MovieClip
		/**
		 * 图片组点击对象
		 * @param e
		 * 
		 */		
		private function viewClickHandle(e:MouseEvent):void
		{
			if(_bindChooseIndex != -1 && _chooseEquip != null&&!(_chooseEquip is ObjectData))
			{
				_bindManage.UnbindProp(_chooseEquip["data"],"IntensityLevel",_bindChooseIndex);
			}
			_chooseEquip	=	(e.currentTarget as MovieClip)["data"];
			if(_chooseEquip==null||_chooseEquip["data"]["ObjKey"]!=2||_viewID!=1)
			{
				_myDisplay.gogo.visible=false;
			}
			_itemGroupItem=e.currentTarget as MovieClip;
			showClickEquip(_chooseEquip,e.currentTarget as MovieClip);
			changeClickMc(e.currentTarget as MovieClip);
			
		}
		/**
		 *是否显示 一键强化按钮
		 */		
		private function showUpdateStar(obj:Object ,needmoney:Number):int
		{
			var obj_1:Object ={}; 
			if(obj.hasOwnProperty("data"))
			{
				obj_1=(obj["data"]["Properties"])
			}else if(obj.hasOwnProperty("Properties"))
			{
				obj_1=obj["Properties"]
			}
			else
			{
				obj_1=obj
			}
			
			var blueConsume:int = getAddFiveLv(obj_1);
			// 即使刷新 一键强化 显示金钱TIPS  
//			TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000682" ,[blueConsume])) ; 
			if(_model.scene.Role.getPlayerLevel()-obj_1.IntensityLevel>=5)
			{
				_myDisplay.updateStart.enabled=true; 
				if(_model.scene.Role.getGoldCoin()>=blueConsume)
				{
					_GoldIs = true;
//					_myDisplay.updateStart.enabled=true; 
				}else
				{
					_GoldIs =false ;
					_myDisplay.updateStart.enabled=false; 
//					_myDisplay.updateStart.enabled=true; 
				}
				
			}else
			{
				_GoldIs =false ;
				_myDisplay.updateStart.enabled=false; 
			}
			return blueConsume ;
		}
		/**
		 * 鼠标移入 
		 * @param e
		 * 
		 */		
		private function viewOverHandle(e:MouseEvent):void
		{
			var tempMC:MovieClip	=	e.currentTarget as MovieClip;
			if(tempMC["Back"].currentFrame != 3)
			{
				tempMC["Back"].gotoAndStop(2);
			}
			if(tempMC["data"] != null)
			{
				TipsMainLogic.instance.showMain(tempMC["data"]["data"]);
			}
		}
		/**
		 * 鼠标移出 
		 * @param e
		 * 
		 */		
		private function viewOutHandle(e:MouseEvent):void
		{
			var tempMC:MovieClip	=	e.currentTarget as MovieClip;
			if(tempMC["Back"].currentFrame != 3)
			{
				tempMC["Back"].gotoAndStop(1);
			}

			TipsMainLogic.instance.hide();
		}
		/**
		 * 选择装备的信息显示
		 * @param e
		 * 
		 */		
		private function clipOverHandle(e:MouseEvent):void
		{
			if(_chooseEquip != null)
			{
				TipsMainLogic.instance.showMain(_chooseEquip["data"]);
			}
		}
		/**
		 * 选择装备的信息关闭
		 * @param e
		 * 
		 */		
		private function clipOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * 
		 * @param e
		 * 
		 */		
		private function tipsOverHandle(e:MouseEvent):void
		{
			if(Tips==null)return ; 
			TipsMainLogic.instance.showMain(Tips);
		}
		private function tipsOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * 添加人物页签 
		 * @param ObjID
		 * @param Obj
		 * @param data
		 * 
		 */		
		private function addItem(ObjID:String,Obj:BaseObject,data:*):void
		{
			_friendnObj[ObjID]	=	Obj;
			showTab();
		}
		/**
		 * 移除页签项 
		 * @param ObjID
		 * @param Obj
		 * @param data
		 * 
		 */		
		private function removeItem(ObjID:String,Obj:BaseObject,data:*):void
		{
			_friendnObj[ObjID]	= null;
			showTab();
		}
		/**
		 *重写伙伴标签 
		 */		
		private function showTab():void
		{
			if(_tabArr[0]==null) return ; 
			_friendTabArray	=	[];
			var checkItem:BaseObject
			var arr:Array = [] ; 
			//先压入自己
			_friendTabArray.push({label:_model.scene.Role.getPlayerName(),data:_roleBaseObj});
			// 在压 上阵的
			var i :uint = 0 ; 
			for(i; i<_tabArr[0].length; i++)
			{
				if(_tabArr[0][i] is ViewObject)
				{
					checkItem=_tabArr[0][i] as BaseObject;
					arr.push(checkItem["ObjKey"]);
					_friendTabArray.push({label:StaticIni.getSwfLangStr(checkItem.GetProperties("ConfigID")),data:checkItem});
				}
			}
			//不上阵的
			for(var str:String in _friendnObj)
			{
				checkItem	=	_friendnObj[str];
			
				if(checkItem != null)
				{
					if(updateList(arr,checkItem["ObjKey"]))
					{
						_friendTabArray.push({label:StaticIni.getSwfLangStr(checkItem.GetProperties("ConfigID")),data:checkItem});
					}
					
				}
			}
			//压入背包
//			_friendTabArray.push({label:"背包",data:_packBaseObj});
			
			_myDisplay.roleTab.dataProvider	=	_friendTabArray;

		}
		/**
		 *
		 *  
		 * @param e
		 * 
		 */
		private function updateList(arr:Array ,value:int):Boolean
		{
			var j :uint = 0 ; 
			for(j ; j<arr.length ; j++)
			{
				if(value==arr[j])
				{
					return false 
//					_friendTabArray.push({label:checkItem.GetProperties("Name"),data:checkItem});
				}
			}
			return true ; 
		}
		/**
		 * 伙伴页签点击 
		 * @param e
		 * 
		 */		
		private function tabClickHandle(e:NxTabEvent):void
		{
			var friendItem:BaseObject	=	e.item["data"];
			if(friendItem != null)
			{
				var friendEquipViewID:int
				if(friendItem.GetProperties("ConfigID") == -1 ||friendItem.GetProperties("ConfigID") == -2)
				{
					if(friendItem.GetProperties("ConfigID") == -1 )
						peoType = _model.scene.Role["Properties"]["ProfType"];
						
					friendEquipViewID	=	friendItem.GetProperties("viewID");
				}
				else
				{
					peoType = friendItem["Properties"]["ProfType"];
					
					/** * 获取指定伙伴身上的装备视图号*/
					friendEquipViewID	=	getEquipView(friendItem.GetProperties("ConfigID"));
				}
				if(_viewID != -1)
				{
					_bindManage.UnbindView(_viewID,_bindIndex);
				}
				_friendEquipObj		=	{};
				_viewGroupTrun.dataProvider	=	[];
				_viewID				=	friendEquipViewID;
				_bindIndex			=	_bindManage.BindView(_model.scene,_viewID,addEquipItem,removeEquipItem);	
				checkItemEquip();
			}
			if(_viewID!=1)
			{
				_myDisplay.gogo.visible =false ; 
			}
		}
		/**
		 * 添加装备 
		 * @param ObjID
		 * @param Obj
		 * @param data
		 * 
		 */		
		private function addEquipItem(ObjID:String,Obj:BaseObject,data:*):void
		{
			if(Obj.GetProperties("ItemType") == "106")
			{
				_friendEquipObj[ObjID]	=	Obj;
				checkItemEquip();
			}
			
		}
		/**
		 * 移除装备 
		 * @param ObjID
		 * @param Obj
		 * @param data
		 * 
		 */		
		private function removeEquipItem(ObjID:String,Obj:BaseObject,data:*):void
		{
			if(Obj.GetProperties("ItemType") == "106")
			{	
				_friendEquipObj[ObjID]	=	null;
//				checkItemEquip();
			}
			
		}
		/**
		 * 关闭窗口 
		 * @param e
		 */
		private function windowCloseHandle(e:NxWindowEvent):void
		{
			_myDisplay.hide();
		}
		/**
		 * 显示单个显示对象 
		 * @param mc	
		 * @param val
		 * 
		 */		
		private function showEquipItem(mc:MovieClip,val:Object,configID:int=0):void
		{
			
			if(val != null)
			{
				
				(mc["pic"] as NxClip).source			=	ResourcesPath.getPropsURL(int(StaticIni.getSwfLangStr(val["data"].GetProperties("Photo"))));
				(mc["pic"] as NxClip).filters			=[]
				var str:String							=	link_color(StaticIni.getSwfLangStr(val["data"].GetProperties("ConfigID")),
																	val["data"].GetProperties("Color"));
				(mc["titleTxt"] as TextField).htmlText	=	str;
				//(mc["infoTxt"] as TextField).htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_2",[val["data"].GetProperties("IntensityLevel")]);
				(mc["infoTxt"] as TextField).htmlText	=	"";
				mc["data"]								=	val;
				mc["title"].htmlText					=	StaticIni.getSwfLangStr("UIStr_1001617")
				mc["bindIndex"]						=	_bindManage.BindProp(mc["data"]["data"],"IntensityLevel",mc["infoTxt"],"htmlText");
				if(ComposeItemLogic.getInstance().searchItem(val["data"].GetProperties("UpgradeScroll"),1)>0)
				{
					(mc["pic1"] as NxClip).source		=	ResPath.PNG+"eq0.png" ; 
				}else
				{
					(mc["pic1"] as NxClip).source		=""  ; 
				}
			}
			else
			{
				if(configID==-1)return ;
				var obj:Object = StaticIni.getIniObj(configID.toString()) as Object;
				/**图片*/
				(mc["pic"] as NxClip).source			= ResourcesPath.getPropsURL(obj["Photo"]); 
				(mc["pic"] as NxClip).filters			=[FilterUtil.GrayColorFilter]
				/**名字**/
				var str_1:String	 						=link_color(StaticIni.getSwfLangStr("EquipStr_"+mc["type"]) ,0); 
				(mc["titleTxt"] as TextField).htmlText	 =str_1 ;
				(mc["infoTxt"] as TextField).htmlText	=	"";
				
				mc["title"].htmlText					=	StaticIni.getSwfLangStrVar("NewItemChangeUIStr_42",[0]);
				(mc["pic1"] as NxClip).source		=""  ; 
			}
		}
		/**
		 * 移除单个显示对象
		 * @param mc
		 */		
		private function removeMcEquipItem(mc:MovieClip):void
		{
			arrEquip= [] ; 
			if(mc["bindIndex"] != null)
			{
				_bindManage.UnbindProp(mc["data"]["data"],"IntensityLevel",mc["bindIndex"]);
			}
			mc["bindIndex"]							=	null;
			mc["data"]									=	null;
			if(mc["pic"] != null)
			{
				(mc["pic"] as NxClip).source			=	null;
			}
			if(mc["titleTxt"] != null)
			{
				(mc["titleTxt"] as TextField).htmlText	=	""
			}
			if(mc["infoTxt"] != null)
			{
				(mc["infoTxt"] as TextField).htmlText		=	""
			}
			if(mc["title"] != null)
			{
				(mc["title"] as NxLabel).htmlText		=	""
			}
			if(mc["Back"] != null)
			{
				(mc["Back"] as  MovieClip).gotoAndStop(1);
			}
		}
		/**
		 * 翻页后的操作
		 */
		public function afterShowItem():void
		{
			var data:Object	=	_myDisplay.itemGroup.getItemByIndex(0)["data"] as Object
			_chooseEquip	=	data
				
			showClickEquip(_chooseEquip,_myDisplay.itemGroup.getItemByIndex(0) as MovieClip);
			
			changeClickMc(_myDisplay.itemGroup.getItemByIndex(0));
		}
		/**
		 * 检测人物物品 
		 */		
		private function checkItemEquip():void
		{
			
			_friendEquipArray	=	[];
			var itemBaseObj:BaseObject
			for(var str:String in _friendEquipObj)
			{
				itemBaseObj	=	_friendEquipObj[str];
				if(itemBaseObj != null)
				{
					var itemObj:Object		=	{};
					itemObj["viewID"]		=	_viewID;
					itemObj["data"]			=	itemBaseObj;
					_friendEquipArray.push(itemObj);
				}
			}
//			_viewGroupTrun.dataProvider	=	_friendEquipArray;
			initEquip(_friendEquipArray)
		}
		
		/**
		 * 
		 * @param configID
		 * @return 
		 * 初始化装备
		 */		
		private function initEquip(arr:Array):void
		{
			var i:uint = 0;  
			for(i;i<_itemMax ; i++)
			{
				var itemBox:MovieClip	=	_myDisplay.itemGroup.getItemByIndex(i) as MovieClip;
				getEquip(arr,itemBox);
				getArrEquip(itemBox);
			}
			if(_itemGroupItem)
			{
				var data:Object	=	_itemGroupItem["data"] as Object
				_chooseEquip	=	data;
				showClickEquip(_chooseEquip,_itemGroupItem);
				_itemGroupItem = null ; 
			}
			else
			{
				var data1:Object	=	_myDisplay.itemGroup.getItemByIndex(0)["data"] as Object
				_chooseEquip	=	data1;
				showClickEquip(_chooseEquip,_myDisplay.itemGroup.getItemByIndex(0) as MovieClip);
			}
			
		}
		
		/**
		 * 初始化装备的
		 */		
		private function getEquip(arr:Array,itemBox:MovieClip):void
		{
//			 arrEquip= [] ; 
			
			var j:uint= 0 ; 
			for(j;j<arr.length;j++)
			{
				var obj:Object= arr[j]["data"];
				if(_viewID==1&&obj["ObjKey"]==2)
				{
					_tipsShow = true ; 
				}
				if(itemBox["type"] == obj["ObjKey"])
				{
					
					arrEquip.push(itemBox["type"])
					showEquipItem(itemBox,(arr[j] as Object))
				}
			}
		}
		/**
		 * 
		 * @param configID
		 * @return 
		 * 
		 */	
		private function getArrEquip(itemBox:MovieClip):void
		{
			var isOk:Boolean =true ; 
			var i:uint = 0 ; 
			for( i ; i<arrEquip.length ; i++ )
			{
				if(itemBox["type"]==arrEquip[i])
				{
					isOk= false  ; 
				}
			}
			if(isOk)
			{
//				SubItemType
				if(itemBox["type"]==2)
				{
					var obj:Object = StaticIni.getIniObj(equipInitID(itemBox["type"]).toString()); 
					weap = obj["SubItemType"] ; 
				}
				
				showEquipItem(itemBox,null,equipInitID(itemBox["type"]))
			}
			
			
		}
		
		/**
		 * 获取指定伙伴身上的装备视图号
		 * @param configID
		 * 
		 */		
		public function getEquipView(configID:int):int
		{
			//单个伙伴装备个数
			var equipLenght:int;
			//伙伴个数
			var arrayLenght:int;
			var returnInt:int	=	-1;
			//伙伴表格
			var equipArray:Array	=	_model.scene.GetRecordEx("PartnerViewIDRec").recArr;
			if(equipArray != null)
			{
				arrayLenght		=	equipArray.length;
				for(var i:int = 0; i < arrayLenght ; i++)	
				{
					if(equipArray[i][0] == configID)
					{
						returnInt	=	equipArray[i][1];
					}
				}
			}
			return returnInt;
		}
		/**
		 * 初始化显示图片组
		 */		
		private function inforViewGroup():void
		{
			for(var i:int = 0; i < _myDisplay.itemGroup.col * _myDisplay.itemGroup.row; i++)
			{
				var itemBox:MovieClip	=	_myDisplay.itemGroup.getItemByIndex(i) as MovieClip;
				if(itemBox != null)
				{
					var pic:NxClip			=	new NxClip();
					var pic1:NxClip			=	new NxClip();
					pic1.x  =22;
					pic1.y  =22;
					var backTxt:NxLabel		=	new NxLabel();
					/***装备类型**/
					itemBox["type"]			=equipType(i);
						
					itemBox["pic"]			=	pic;
					itemBox["pic1"]			=	pic1;
					pic.isCache				=	true;
					pic1.isCache			=	true;
					itemBox["img2"].addChild(pic);
					itemBox["img2"].addChild(pic1);
					itemBox["titleTxt"]	=	itemBox.getChildByName("titleTxt") 	as TextField;
					itemBox["infoTxt"]		=	itemBox.getChildByName("infoTxt") 		as TextField;
					itemBox["Back"]			=	itemBox.getChildByName("dt_mc") 		as MovieClip;
					itemBox["index"]		=	i;
					itemBox["title"]		=	backTxt;
					pic.source				=	null;
					pic1.source				=	null;
					(itemBox["titleTxt"] 		as TextField)	.htmlText	=	"";
					(itemBox["infoTxt"]		as TextField)	.htmlText	=	"";
					itemBox["titleTxt"].htmlText							=	"";
					(itemBox["infoTxt"]		as TextField).width	=	50;
					(itemBox["infoTxt"]		as TextField).x		=	95
					itemBox["Back"].gotoAndStop(1);
					backTxt.x			=	55;
					backTxt.y			=	itemBox["infoTxt"].y;
					itemBox.addChild(backTxt);
					itemBox.mouseChildren	=	false;
				}
			}
		}
		/**
		 * 材料图片
		 * 
		 */
		private function awardInfo():void 	
		{
			var count:uint  = _myDisplay.stuff.row*_myDisplay.stuff.col; 
			var i :uint  =0  ; 
			for(i;i<count;i++)
			{
				var itemMC:MovieClip=_myDisplay.stuff.getItemByIndex(i);
				var Image:NxClip= new NxClip(); 
				var label:NxLabel = new NxLabel();
				label.color = 0xffffff ; 
				label.x = 12;
				label.y =40;
				
				Image.isCache = true ; 
				itemMC["img2"].addChild(Image) ; 
				itemMC["image"] = Image ; 
				itemMC["label"] = label ; 
				itemMC["img2"].addChild(label) ;
				itemMC.visible = false; 
			}
			
		}
		/**
		 * 
		 * @param val
		 * 每个装备格子的类型
		 */
		private function equipType(value:uint):int 
		{
			switch(value)
			{
				case 0:
					return 2 ;  
					break ;
				case 1:
					return 4 ;  
					break ; 
				case 2:
					return 5 ;  
					break ; 
				case 3:
					return 3 ;  
					break ; 
				case 4:
					return 6 ;  
					break ; 
				case 5:
					return 1 ;  
					
					break ; 
			}
			
			return -1;
		}
		/**
		 * 
		 * @param val
		 * 初始化 装备格子 灰掉的格子
		 */
		private function equipInitID(value:int):int
		{
			switch(value)
			{
			
				case 1:
					return 31101002	;
					break ;  
				case 2:
					if(peoType==1)
					{
						return 31031002	;
						
					}else if (peoType==2||peoType==3)
					{
						return 31011002	;
						
					}else
					{
						return 31051002	;
					}
					
					break ;
				case 3:
					return  31081002
					break ; 
				case 4:
					return  31061002;
					break ; 
				case 5:
					return 31071002;
					
					break ; 
				case 6:
					return 31091002;
					break ; 
			}
			
			return -1;
		}
		/**
		 * 显示当前点击的装备物品
		 * @param val
		 * 
		 */		
		private function showClickEquip(val:Object,mc:MovieClip):void
		{	
			_isNowItem								=	false;
			var str:String;	
			_myDisplay.lab_needmoney.color			=	0x00FF00;
			var Obj:Object ={}; 
			ClearViewGround();
			if(val != null)
			{
				
				/**装备名字*/
				_myDisplay.equipname.htmlText ="";
				/**强化等级**/
				_myDisplay.addLevel.htmlText  =""; 
				_myDisplay.lab_prop4.htmlText ="";
				_myDisplay.lab_prop5.htmlText ="";
				_myDisplay.lab_prop6.htmlText ="";
				
				_myDisplay.lab_needwhat.htmlText 	=StaticIni.getSwfLangStr("UIString_1000522");
				_myDisplay.equipPic.source			=	ResourcesPath.getPropsURL(int(StaticIni.getSwfLangStr(val["data"].GetProperties("Photo"))));
				str									=	link_color(StaticIni.getSwfLangStr(val["data"].GetProperties("ConfigID")),val["data"].GetProperties("Color"));
				_myDisplay.nowUpItemName.htmlText	=	"<font  size='15'><b>" +StaticIni.getSwfLangStrVar("EquipModifiedUIStr_1",[str]) +"</b></>" 
				_myDisplay.lab_prop1.htmlText		=	"";
//				_myDisplay.lab_cdtime.htmlText		=	"";
				_myDisplay.lab_prop2.htmlText		=	"";
				_myDisplay.lab_prop3.htmlText		=	"";
				resfhPro();
				//--------------------------------------------------//
				//"当前可制作" ;
				_myDisplay.lab_getwhat.htmlText  	=StaticIni.getSwfLangStr("UIString_1000521");
				//制作按钮
				_myDisplay. btn_1.visible 			= true 		; 
				//穿戴按钮
				_myDisplay. btn_2.visible 			= false		;
				//强化按钮
				_myDisplay. btn_start.visible 		= true 		; 
				//显示这一页的组件
				falseAndTrue(true,false) ; 
				// 绑定装备等级
				_bindChooseIndex					=	_bindManage.BindProp(val["data"],"IntensityLevel",this,"Level");
				//背包内有装备
				_myDisplay.label_3.visible 			= false  	;
				//显示下一级装备材料
				getAddEquipStuff(val);
				//是否显示 立即制作按钮
				setVipBtn(val)
				/****临时添加***/
				if(val["data"].GetProperties("NeedLevel")>=90)
				{
					_myDisplay.label_4.visible 		= false ;
					
					_myDisplay.btn_1.visible 		= false ;
					_myDisplay.btn_4.visible 		= false ;
					_myDisplay.bgpic.visible 		= false ;
					
					
				
					_myDisplay.addLevel.visible 		= false ;
					_myDisplay.equipname.visible 		= false ;
					_myDisplay.equipPic_1.visible 		= false ;
					_myDisplay.	lab_prop4.visible 		= false ;
					_myDisplay.	lab_prop5.visible 		= false ;
					_myDisplay.	lab_prop6.visible 		= false ;
					
					
				}else
				{
					_myDisplay.btn_1.visible 		= true ;
//					if(_model.scene.Role.getVipLevel()>=4){
//						_myDisplay.btn_4.visible 		= true ;
//					}
				
					_myDisplay.bgpic.visible 		= true ;
					_myDisplay.label_4.visible 		= true ;
					
					
					_myDisplay.addLevel.visible 		= true ;
					_myDisplay.equipname.visible 		= true ;
					_myDisplay.equipPic_1.visible 		= true ;
					_myDisplay.	lab_prop4.visible 		= true ;
					_myDisplay.	lab_prop5.visible 		= true ;
					_myDisplay.	lab_prop6.visible 		= true ;
				}

				
			}
			else
			{
				_myDisplay.equipPic.source		=	null;
				_myDisplay.nowUpItemName.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_1",[""]);
				_myDisplay.nowUpItemLevel.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_2",[""]);
				_myDisplay.lab_needmoney.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_3",[StaticIni.getSwfLangStr("UIString_1000647")]);
				_myDisplay.lab_prop1.htmlText		=	"";
				_myDisplay.lab_prop2.htmlText		=	"";
				_myDisplay.lab_prop3.htmlText		=	"";
				_myDisplay.btn_start.enabled		=	false;
//				_myDisplay.lab_cdtime.htmlText		=	"";
				/**装备名字*/
				_myDisplay.equipname.htmlText ="";
				/**强化等级**/
				_myDisplay.addLevel.htmlText  =""; 
				_myDisplay.lab_prop4.htmlText ="";
				_myDisplay.lab_prop5.htmlText ="";
				_myDisplay.lab_prop6.htmlText ="";
				if(mc!=null)
				{
//					var vieobj:ViewObject=ComposeItemLogic.getInstance().searchItem(equipInitID(mc["type"]),2);
					 var arrList:Array = getPackEquip(mc["type"]);
			 		 _myDisplay.lab_needwhat.htmlText =StaticIni.getSwfLangStr("UIString_1000519");
					 if(arrList.length==0)
					 {
						
						 //立即购买
						 Obj =  TipsMainLogic.instance.getStaticObjWithID(equipInitID(mc["type"]).toString()); 
						 _myDisplay.pic_1.source  = ResourcesPath.getPropsURL(int(Obj["Photo"]));
						 Tips=EquipModifiedLogic.getInstance().getCurrLvItemObject(equipInitID(mc["type"]).toString(),0,Obj["Color"]);
						 _myDisplay.label_1.htmlText ="<font  size='15'><b>" +link_color(StaticIni.getSwfLangStr(Obj["NameID"]),Obj["Color"]) +"</b></>"  ;
						 if(_model.scene.Role.getGoldCoin()<int(Obj["BuyValue"]))
						 {
							 _myDisplay.label_2.htmlText ="<font color='#ff0000'>"+StaticIni.getSwfLangStr("UIStr_1001374")+Obj["BuyValue"]+"</font>";
						 }else
						 {
							 _myDisplay.label_2.htmlText = StaticIni.getSwfLangStr("UIStr_1001374")+Obj["BuyValue"];
						 }
						
						 
						 _myDisplay. btn_start.visible = false ; 
						 _myDisplay. btn_2.visible = false ;
						 _myDisplay. btn_1.visible = false ;
						 
						 falseAndTrue(false,true) ; 
						 _myDisplay.btn_4.visible =false ;
						 _myDisplay.label_3.visible = false  ;
						 _myDisplay.label_4.visible = false  ; 
							 
							 
					 }else
					 {
						 falseAndTrue(true, false) ; 
						 _myDisplay.lab_needmoney.visible =false ; 
						 _myDisplay.nowUpItemName.visible = false; 
						 _myDisplay.nowUpItemLevel.visible = false ;
						 _myDisplay.label_3.visible = true ;
						 _myDisplay.label_4.visible = false  ; 
						 _myDisplay. btn_start.visible = false ;
						 _myDisplay. btn_1.visible = false ; 
						 _myDisplay. btn_2.visible = true ;
						 _myDisplay.btn_4.visible =false ;
						 _myDisplay.updateStart.visible =false ; 
						 
						 _myDisplay.lab_getwhat.htmlText =StaticIni.getSwfLangStr("UIString_1000523");
							// "可穿戴装备";
						 
						var equipObj:Object =  getSuitEquip(arrList);
						 Obj =  StaticIni.getIniObj(equipObj["Properties"]["ConfigID"])
						_myDisplay.equipPic_1.source  = ResourcesPath.getPropsURL(int(Obj["Photo"]));
					
						Tips=EquipModifiedLogic.getInstance().getCurrLvItemObject(equipObj["Properties"]["ConfigID"],equipObj["Properties"]["IntensityLevel"],Obj["Color"]);
						
						/**装备名字*/
						_myDisplay.equipname.htmlText ="<font  size='15'><b>" + link_color(StaticIni.getSwfLangStr(Obj["NameID"]),Obj["Color"]) +"</b></>";
							
						/**强化等级**/
						_myDisplay.addLevel.htmlText =StaticIni.getSwfLangStrVar("EquipModifiedUIStr_2",[equipObj["Properties"]["IntensityLevel"]]); 
						
						
						
						var i :uint  =0  ;
						for(i;i<3;i++)
						{
							if(Obj["AddPropNo"+i]==null)break ; 
							var str_0:String = Obj["AddPropNo"+i] ; 
							var str_1:String = str_0.slice(0,3)
							var str_2:String = str_0.slice(3); 
							_myDisplay["lab_prop"+(i+4)].htmlText = StaticIni.getSwfLangStrVar("ItemProp_"+str_1,[int(str_2)+getNum(i+3)]) ; 
						}
						function getNum(type:int):int
						{
							var proStr2:String	=	equipObj.GetProperties("AddPropNo" + type)
							if(proStr2 != "0")
							{
								var itemArray2:Array	=	[];
								var nameStr2:String	=	"ItemProp_" + proStr2.substr(0,3);
								var proNum2:int		=	int(proStr2.substr(3,proStr2.length));
							}
							return proNum2;
						}
						Obj=equipObj
					 }
					 _chooseEquip=Obj;
				}
				
				
			}
		}
		/**
		 * 
		 *隐藏和现实不同界面不同的组件
		 */
		private function falseAndTrue(value:Boolean,value_1:Boolean):void
		{
			_myDisplay.nowUpItem.visible = value; 
			_myDisplay.equipPic.visible = value; 
			_myDisplay.equipPic_1.visible = value; 
			_myDisplay.bgpic.visible = value; 
			_myDisplay.nowUpItemName.visible = value; 
			_myDisplay.nowUpItemLevel.visible = value; 
			_myDisplay.lab_getwhat.visible = value; 
			_myDisplay.back4.visible = value; 
			_myDisplay.lab_needmoney.visible =value ; 
			//直接强化
			_myDisplay.updateStart.visible =value ; 
			
			
			
			
			/**多余隐藏的**/
			_myDisplay.pic_1.visible =value_1; 
			_myDisplay.bgpic_1.visible =value_1; 
			_myDisplay.btn_3.visible =value_1 ;
			
			_myDisplay.label_1.visible =value_1 ;
			_myDisplay.label_2.visible =value_1 ;
			
//			_myDisplay.lab_needwhat.visible =value_1 ;
//			_myDisplay.back3.visible =value_1 ;
			_myDisplay.backIma.visible = value_1 ;
		
			
		}
		/***清除强化下一等装备的图片资源***/
		private function ClearViewGround():void
		{
			var count:uint  = _myDisplay.stuff.row*_myDisplay.stuff.col; 
			var i :uint  = 0 ; 
			for( i ; i <count;i++)
			{
				var itemMC:MovieClip=_myDisplay.stuff.getItemByIndex(i);
				itemMC["image"].source = ""; 
				itemMC["label"].htmlText = ""; 
				itemMC.visible =false; 
			}
			_myDisplay.equipPic_1.source ="";
			_myDisplay.pic_1.source  = ""; 
		}
		/**
		 * 
		 * @param val
		 * 下一等级装备所需的装备材料----收集下一级装备材料_stuffArr
		 * 
		 */
		private function getAddEquipStuff(obj:Object):void
		{
			if(obj==null )return ; 
			_stuffArr = []; 
			var id:int=obj["data"].GetPropertiesEx("UpgradeScroll");
			var arr:Array =[] ; 
			if(id !=0)
			{
				var _obj:Object = StaticIni.getIniObj("ProduceItem_"+id.toString());
				var str:String = _obj["r"]
				arr=str.split(",");
				for (var i:int = 2;i<arr.length;i++)
				{
					if(arr[i]!="")
					{
						_stuffArr.push(arr[i])
					}
				}
				_stuffArr.push(id);
				_stuffArr.push(1);
				/***显示材料**/
				showAddEquip(_stuffArr);
				/**
				 * 
				 * @param arr
				 * 判断是否满足制作条件
				 * 是否显示制作按钮
				 * */
				if(isShowBtn(_stuffArr))
				{
//					_myDisplay.btn_1.visible= true ;
					_myDisplay.btn_1.enabled=true ; 
				}else
				{
					_myDisplay.btn_1.enabled=false ; 
				}
			}
			
		}
		/**
		 * 
		 * @param arr
		 * 判断是否满足制作条件
		 * 是否显示制作按钮
		 * 
		 */
		private function isShowBtn(arr:Array):Boolean
		{
			var i :uint = 0 ; 
			for(i ; i<arr.length;i+=2 )
			{
				var vieobj:uint=ComposeItemLogic.getInstance().searchItem(arr[i],1);
				if(vieobj==0)
				{
					return false ; 
				}else
				{
					if(vieobj<arr[i+1])
					{
						return false ; 
					}
				}
				
			}
			return true ; 
		}
		/**
		 * 显示装备材料
		 * 
		 */		
		private function showAddEquip(arr:Array):void
		{
			if(arr.length==0 ||arr==null)return  ;
		
			var count:uint  = _myDisplay.stuff.row*_myDisplay.stuff.col; 
			var i :uint =0 ; 
			var str:String = "" ; 
			for(i ; i<count; i++)
			{
				var itemMC:MovieClip=_myDisplay.stuff.getItemByIndex(i);
				
				if(i<arr.length/2)
				{
					itemMC.visible = true ; 
					var _obj:Object=StaticIni.getIniObj(arr[i*2]);
					
					itemMC["image"].source = ResourcesPath.getPropsURL(int(_obj["Photo"]));
					itemMC["configID"] = arr[i*2] ; 
					var vieobj:uint=ComposeItemLogic.getInstance().searchItem(arr[i*2],1);
					if(vieobj==0)
					{
						str = "0"+"/"+arr[(i*2)+1];  
						itemMC["label"].htmlText =str ; 
						
					}else
					{
						if(vieobj<arr[(i*2)+1])
						{
							str = vieobj+"/"+arr[(i*2)+1]; 
							itemMC["label"].htmlText =str;
							itemMC["label"].x=10-sizeWidth(str);
						}else
						{
							str = vieobj+"/"+arr[(i*2)+1];
							itemMC["label"].htmlText ="<font color='#1eff00'>"+str+"</font>";
							itemMC["label"].x= 10-sizeWidth(str) ;
						}
					}
					
				}else
				{
					itemMC.visible = false;  
				}
			}
			showTipsAndEquip(_stuffArr);
		}
		private function sizeWidth(str:String):int
		{
			if(str.length -3>0)
			{
				return int((str.length -3)*3)
			}else
			{
				return 	 0 ; 
			}
				
		}
		/**
		 * 
		 * @param val
		 * 制作下一级装备的 TIPS
		 * 制作后的等级 
		 * 攻击力
		 * 
		 */		
		private function showTipsAndEquip(arr:Array):void
		{
			/***/
			if(arr.length==0)return ; 
			
			var equipObj:Object = StaticIni.getIniObj(arr[arr.length -2]);
			var obj_1:Object=StaticIni.getIniObj(equipObj["GetItem"]);
			_myDisplay.equipPic_1.source  = ResourcesPath.getPropsURL(int(obj_1["Photo"]));
			if(addLv<=5)
			{
				Tips=EquipModifiedLogic.getInstance().getCurrLvItemObject(equipObj["GetItem"],0,equipObj["Color"]);
			}else
			{
				Tips=EquipModifiedLogic.getInstance().getCurrLvItemObject(equipObj["GetItem"],addLv-5,equipObj["Color"]);
			}
			/**装备名字*/
			_myDisplay.equipname.htmlText ="<font  size='15'><b>" + link_color(StaticIni.getSwfLangStr(Tips["NameID"]),Tips["Color"]) +"</b></>"; 
			/**强化等级**/
			_myDisplay.addLevel.htmlText =StaticIni.getSwfLangStrVar("NewItemChangeUIStr_42" ,[Tips["IntensityLevel"]])
			  
			for(var i:uint=0 ;i<3;i++)
			{
				var str:String = Tips["AddPropNo"+i] ; 
				if(str=="0"){
					
					_myDisplay["lab_prop"+(i+4)].htmlText=""; 
					
				}else
				{
					var str_1:String = str.slice(0,3)
					var str_2:String = str.slice(3); 
					_myDisplay["lab_prop"+(i+4)].htmlText = StaticIni.getSwfLangStrVar("ItemProp_"+str_1,[int(str_2)]) ; 
				}
					
				
			}
			
		
		}
		/**
		 * 当前物品强化的等级
		 * @param val
		 * 
		 */		
		public function set Level(val:int):void
		{
			
			addLv = val ; 
//			if(!_isNowItem)
//			{
//////				_isNowItem	=	true;
//			}
//			else
//			{
////				_myDisplay.effect.gotoAndPlay(1);
////				_myDisplay.effect.visible	=	true;
////				_myDisplay.effect.addFrameScript(_myDisplay.effect.totalFrames - 1,mcOverHandle)
//			}
			_myDisplay.nowUpItemLevel.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_2",[val]);
			if(val  >=  _model.scene.Role.getPlayerLevel())
			{
				_myDisplay.lab_needmoney.htmlText	=	StaticIni.getSwfLangStr("EquipModifiedUIStr_9")
				_levelMax	=	true;
				_myDisplay.btn_start.enabled	=	false;
			}
			else
			{
				_levelMax	=	false;
				if(_chooseEquip == null||!((_chooseEquip.hasOwnProperty("data")&&_chooseEquip["data"] is BaseObject)))return ;//||_chooseEquip["data"]==null)return;
				var needMoney:Number	=	getNeedMoney(int(_chooseEquip["data"].GetProperties("IntensityLevel") + 1),int(_chooseEquip["data"].GetProperties("Color")),_chooseEquip["data"].GetProperties("EquipType"))
				_myDisplay.lab_needmoney.htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_3",[needMoney]);
				if(_model.scene.Role.getGoldCoin() >=needMoney)
				{
					_myDisplay.lab_needmoney.color	=	0x00FF00;
					_isNeedMoeny = true
					_myDisplay.btn_start.enabled	=	true;
				}
				else
				{
					_myDisplay.lab_needmoney.color	=	0xFF0000;
					_isNeedMoeny	= false;
					_myDisplay.btn_start.enabled	=	false;
				}
			}
			resfhPro();
			//是否显示 一键强化按钮
			 var needBtnMoney:int  = showUpdateStar(_chooseEquip,needMoney);
			
			if(_levelUpdate==false)
			{
				
				if(currBtn==(_myDisplay.btn_start as NxButton))
				{
					MsgTipsLogic.getRes((_myDisplay.btn_start as NxButton),0).showInfo(StaticIni.getSwfLangStr("UIString_1000669"),false);
				}else
				{
					MsgTipsLogic.getRes((_myDisplay.updateStart as NxButton),0).showInfo(StaticIni.getSwfLangStr("UIString_1000669"),false);
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("UIString_1000682" ,[needBtnMoney])) ;
				}
				_levelUpdate =true ; 
				_isNowItem	=	true;
				
				_myDisplay.effect.gotoAndPlay(1);
				_myDisplay.effect.visible	=	true;
				_myDisplay.effect.addFrameScript(_myDisplay.effect.totalFrames - 1,mcOverHandle)
			}
			showTipsAndEquip(_stuffArr);
			//如果主角初始武器没有到五级就显示箭头 
			specific(val);
		}
		/**
		 *如果主角初始武器没有到五级就显示箭头 
		 * 
		 */		
		private function specific(value:int):void
		{
			if(_chooseEquip["viewID"]==1&&_chooseEquip["data"]["ObjKey"]==2)
			{
				if(value<5)
				{
					_myDisplay.gogo.play();
					_myDisplay.gogo.visible=true ;
				}else
				{
					_myDisplay.gogo.stop();
					_myDisplay.gogo.visible=false  ;
				}
			}
		}
		/**
		 * 阵法表
		 * @param PropertiesName
		 * @param PropertiesValue
		 * @param data
		 * 
		 */		
		private function onaddPerHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			
			var tabCount:int		=	PropertiesValue[0]-1;
			var countInGroup:int	=	PropertiesValue[1];
			var uid:String		= 	PropertiesValue[2];
			var dd:Object;
			if( _tabArr[tabCount]	==	null)
			{
				_tabArr[tabCount]	=	[];
			}
			if(uid&&uid!="0")
			{
				if(uid	==	"-1")
				{
					dd	=	 _tabArr[tabCount][countInGroup]	=	_model.scene.Role; 
				}
				else
				{
					dd	=	 _tabArr[tabCount][countInGroup]	=	_friendnObj[uid];
				}
				
			}
			else
			{
				_tabArr[tabCount][countInGroup]	=	null;
			}
		}
		private function onremovePerHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			
		}
		/**
		 * 交换点击状态 
		 * @param val
		 * 
		 */		
		private function changeClickMc(val:MovieClip):void
		{
			if(_oldMC	!= null)
			{
				_oldMC["Back"].gotoAndStop(1)
			}
			val["Back"].gotoAndStop(3);
			_oldMC	=	val;
//			_myDisplay.effectMc.visible	=	false;
//			_myDisplay.effectMc.x	=	val.x  + 2;
//			_myDisplay.effectMc.y	=	val.y  + 2;
//			if(_oldMC != null)
//			{
//				_oldMC["backMC"].gotoAndStop(1);
//				_oldMC["iconMC"].gotoAndStop(3);
//			}
//			val["backMC"].gotoAndStop(3);
//			if(val["data"] != null)
//			{
//				val["iconMC"].gotoAndStop(2);
//			}
//			else
//			{
//				val["iconMC"].gotoAndStop(3);
//			}
		
		}
		/**
		 * 刷新特殊属性
		 */		
		public function resfhPro():void
		{
//			if(_chooseEquip["data"]==null)return ; 
			var proArray:Array	=	getAddProArray(_chooseEquip["data"]);
			if(proArray.length >0)
			{
				for(var i:int = 0; i <proArray.length; i++ )
				{
					(_myDisplay["lab_prop" + int(i + 1)] as NxLabel).htmlText	=	StaticIni.getSwfLangStrVar("EquipModifiedUIStr_5",proArray[i]);
				}
			}
		}
		/**
		 * 装备强化需要多少钱 
		 * @param level_
		 * @param color_
		 * @param type_
		 * @return 
		 * 
		 */		
		public  function getNeedMoney(level_:int,color_:int,type_:String):Number
		{
			var returnMoney:Number	=	0;
			var coast:Number		=	0
				
//			coast	= 5 * (Math.pow(level_,2.5) + level_ * 5) + 70;
			if(level_  < 17)
			{
				coast = 15+3 * Math.pow(level_,2);
			}
			else if(level_ > 16)
			{
				coast = 0.072 * Math.pow(level_,3.5)-300
			}
			var predNum:Number		=	0;
			switch(type_)
			{
				case "Weapon":
					predNum	=	1;
					break;
				case "Hat":
					predNum	=	0.5;
					
					break;
				case "Clothe":
					predNum	=	0.6;
					break;
				case "Belt":
					predNum	=	0.7;
					break;
				case "Shoe":
					predNum	=	0.5;
					break;
				case "Adorn":
					predNum	=	1.6;
					break;
			}
			switch(color_)
			{
				case 3:
					returnMoney = coast * predNum;
					break;
				case 4:
					returnMoney = (coast * predNum) * 10 /3;
					break;
				case 2:
					returnMoney = (coast * predNum) / 3;
					break;
			}
			return Math.floor(returnMoney);
		}
		/**
		 * 获取特殊属性
		 * @param val
		 * @return 
		 * 
		 */		
		private function getAddProArray(val:BaseObject):Array
		{
			var proArray:Array	=	[];
			for(var i:int = 0; i < 3; i++)
			{
				var proStr:String	=	val.GetProperties("AddPropNo" + i)

				if(proStr != "0")
				{
					var itemArray:Array	=	[];
					var nameStr:String	=	"ItemProp_" + proStr.substr(0,3);
					var proNum:int		=	int(proStr.substr(3,proStr.length))+getNum(i+3);
					itemArray[0]		=	StaticIni.getSwfLangStrVar(nameStr,[proNum]);
					itemArray[1]		=	val.GetProperties("UpgradePropNo" + i);
					proArray.push(itemArray);
				}
			}
			return proArray;
			function getNum(type:int):int
			{
				var proStr2:String	=	val.GetProperties("AddPropNo" + type)
				if(proStr2 != "0")
				{
					var itemArray2:Array	=	[];
					var nameStr2:String	=	"ItemProp_" + proStr2.substr(0,3);
					var proNum2:int		=	int(proStr2.substr(3,proStr2.length));
				}
				return proNum2;
			}
		}
		/**
		 *根据ConfigIDhuo和物品的精炼等级来获取此物品 
		 * @param configid  ID
		 * @param Lv   等级
		 * @return 
		 * 
		 */		
		public function getCurrLvItemObject(configid:String,Lv:int,color:int):Object
		{
			var obj:Object=TipsMainLogic.instance.getStaticObjWithID(configid);//StaticIni.getIniObj(configid);
			var newObj:Object=obj;
			var addProper:String;
			var num:String;
			var addProperName:String; 
			var fountainheadProNum:String; //元和属性的值
			var addProVector:Vector.<UpdateItemProperes>=new Vector.<UpdateItemProperes>();
			for(var i:int=0;i<3;i++)
			{
				addProperName =StaticIni.getIniVar(configid,"AddPropNo"+i);
//				 addProper =addProperName.substr(0,3);
//				 fountainheadProNum=addProperName.substr(3,addProperName.length)
				 num=StaticIni.getIniVar(configid,"UpgradePropNo"+i);
				 addProVector.push(new UpdateItemProperes(addProperName,fountainheadProNum,num));
			}
			
			var currProNum:int;//升级后的值
			for(var j:String in addProVector)
			{
				currProNum=int(addProVector[j].properes)+int(addProVector[j].num)*Lv;
				newObj["AddPropNo"+j]=currProNum;
			}
			newObj["Color"]=color;
			if(Lv>0)
			{
				newObj=setAddGold(newObj,Lv);
			}
			else
			{
	 			newObj["IntensityLevel"]=Lv;
			}
			newObj["ItemFightPower"] =ItemFightPower(addProVector,newObj["IntensityLevel"]);
			return newObj
		}
		private function  ItemFightPower(addProVector:Vector.<UpdateItemProperes>,Lv:int):Number
		{
			var ItemFightPower:Number=0;
			var currProNum:String;//升级后的值
			for(var j:String in addProVector)
			{
				currProNum=(int(addProVector[j].properes)+int(addProVector[j].num)*Lv).toString();
				var properName:String =currProNum.slice(0,3);
				var num:String =currProNum.slice(3,currProNum.length);
				var coefficient:Number =Number(StaticIni.getIniVar(properName,"r1"));
				ItemFightPower+=int(num)*coefficient;
			}
			return ItemFightPower;
		}
		private function getPropersty(obj:Object,proname:String):Number
		{
			if(obj.hasOwnProperty(proname))
			{
				return obj[proname];
			}
			else
			{
				return 0;
			}
			 
		}
		private function setAddGold(obj:Object,lv:int):Object
		{
			var sum:int;
			var currLv:int=0;
				currLv=obj["IntensityLevel"];
			if(currLv >= lv-1)
			{
				return computeGold(obj);
			}
			else
			{
				return setAddGold(computeGold(obj),lv);
			}
			
		}
		private function computeGold(obj:Object):Object
		{
			var color:int=obj.Color;
			var type:String=obj.EquipType;
			var currLv:int=0;
			currLv=int(obj["IntensityLevel"])+1;
			var blueConsume:Number=0;
			if(currLv<16)
			{
				blueConsume = 15 + 3 * Math.pow(currLv, 2);
			}
			else
			{
				blueConsume =0.072 * Math.pow(currLv, 3.5) - 300;
			}
			var pureConsume:Number = blueConsume * 10 / 3;
			var greenConsume:Number = blueConsume / 3;
			var consume:Number = 0;
			switch(color)
			{
				case 2:
					consume = greenConsume;
					break;
				case 3:
					consume = blueConsume;
					break;
				case 4:
					consume = pureConsume;
					break;
				
			}
//			var lastConsume:int = consume * EquipTypeMul(equip);
			var EquipTypeMul:Number;
			switch(type)
			{
				case "Weapon":
					EquipTypeMul =1;
					break;
				case "Hat":
					EquipTypeMul =0.5;
					break;
				case "Clothe":
					EquipTypeMul =0.6;
					break;
				case "Belt":
					EquipTypeMul =0.7;
					break;
				case "Shoe":
					EquipTypeMul =0.5;
					break;
				case "Adorn":
					EquipTypeMul =1.6;
					break;
			}
			obj["SellValue"]=int(obj["SellValue"])+int(EquipTypeMul*consume*0.25);
			obj["IntensityLevel"]=currLv;
			return obj;
		}
		private function mcOverHandle():void
		{
			_myDisplay.effect.stop();
			_myDisplay.effect.visible	=	false;
		}
		private function link_color(str:String,color:int):String
		{
			if(color < 1 || color >8)
			{
				color	=	1;
			}
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		/**
		 * 
		 *搜索装备和武器
		 */		
		private function getPackEquip(type:uint):Array
		{
			
			var packVo:View		=	ModelLocator.getInstance().scene.GetView(View.VIEWPORT_TOOL);
			var value:String = "";
			switch(type)
			{
				case 2:
					value ="Weapon"
					break;
				case 4:
					value ="Hat"
					break;
				case 5:
					value ="Clothe"
					break;
				case 3:
					value ="Belt"
					break;
				case 6:
					value ="Shoe"
					break;
				case 1:
					value ="Adorn"
					break;
			}
			var arr:Array = [] ; 
			if(packVo !=null)
			{
				for (var property:String in packVo.Properties) 
				{
					if(int(property))
					{
						var item:ViewObject=packVo.GetPropertiesEx(property);
						if(item["Properties"]["EquipType"]==value)
						{
							if(value=="Weapon"&&weap ==item["Properties"]["SubItemType"])
							{
								arr.push(item);
							}else if(value!="Weapon")
							{
								arr.push(item);
							}
							
						}
					}
					
				}	
			}
			return arr ; 
		}
		/**
		 * 找到一个适合自己装备
		 * 
		 */
		private function getSuitEquip(arr:Array):Object
		{
			if(arr==null||arr.length==0)return null; 
			var Lv:uint = uint(ModelLocator.getInstance().scene.Role.getPlayerLevel()/10)*10;
			var i :uint =0 ; 
			
			if(arr.length!=0)
			{
				arr.sort(function(item:ObjectData,item2:ObjectData):int{
					if(item.GetPropertiesEx("NeedLevel")==item2.GetPropertiesEx("NeedLevel"))
					return item.GetPropertiesEx("IntensityLevel")-item2.GetPropertiesEx("IntensityLevel")
					return item.GetPropertiesEx("NeedLevel")-item2.GetPropertiesEx("NeedLevel")
						
				
				}); 

			}
			return arr[arr.length-1] 
				
		}
		/**
		 * 
		 * 设置 立即制作按钮
		 */		
		private function setVipBtn(val:Object):void
		{
			if(ComposeItemLogic.getInstance().searchItem(val["data"].GetProperties("UpgradeScroll"),1)>0)
			{
				_myDisplay.btn_4.enabled =true; 
			}else
			{
				_myDisplay.btn_4.enabled =false; 
			}
			if(_model.scene.Role.getVipLevel()>=4)
			{
				_myDisplay.btn_4.visible = true ;
				
			}else
			{
				_myDisplay.btn_4.visible =false ; 
			}
		}
		/**立即制作的Tips**/
		private function getConsume(e:CustomMsgEvent):void
		{
			_needMagicCoin = e.pList[0];
			var str:String =StaticIni.getSwfLangStrVar("UIString_1000486",[_needMagicCoin]);
			TipsMainLogic.instance.showMain(str);
		}
		/***一键强化**/
		private function updateStartHandler(e:MouseEvent):void
		{
			currBtn=e.currentTarget as NxButton;
			if(_GoldIs)
			{
				_levelUpdate=false ;
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_UPGRADE_EQUIP,_chooseEquip["viewID"],int(_chooseEquip["data"]["ObjKey"]),int(INTENSITY_LEVEL));
			}else
			{
				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("99196"));
			}
		
			
		}
		/**
		 * 获取强化五级装备的钱 
		 */		
		private function getAddFiveLv(obj_1:Object):Number
		{
			var i:int =obj_1.IntensityLevel+1 ; 
			
			var color:int=obj_1.Color;
			
			var blueConsume:Number = 0 ;
			var EquipTypeMul:Number = 0 ;
			switch(obj_1.EquipType)
			{
				case "Weapon":
					EquipTypeMul =1;
					break;
				case "Hat":
					EquipTypeMul =0.5;
					break;
				case "Clothe":
					EquipTypeMul =0.6;
					break;
				case "Belt":
					EquipTypeMul =0.7;
					break;
				case "Shoe":
					EquipTypeMul =0.5;
					break;
				case "Adorn":
					EquipTypeMul =1.6;
					break;
			}
			
			for(i; i<=int(obj_1.IntensityLevel+INTENSITY_LEVEL) ; i++)
			{
				if(i<17)
				{
					blueConsume += Math.floor((15 + 3 * Math.pow(i, 2))*EquipTypeMul) ; 
				}
				else
				{
					blueConsume += Math.floor((0.072 * Math.pow(i, 3.5) - 300)*EquipTypeMul);
				}
			}
			var consume:Number = 0;
			switch(color)
			{
				case 3:
					consume = blueConsume ;
					break;
				case 4:
					consume = (blueConsume) * 10 /3;
					break;
				case 2:
					consume = (blueConsume ) / 3;
					break;
			}
			
			
			return consume; 
		}
	}
}

class UpdateItemProperes
{
	public var  properes:String; //强化后增加的属性
	public var  currNum:String;
	public var  num:String;		   //强化一次需要增加本属性的值
	public function UpdateItemProperes(properes:String,currNum:String,num:String):void
	{
		this.properes=properes;
		this.currNum=currNum;
		this.num=num;
	}
}